/*
 * =====================================================================================
 *
 *       Filename:  threeWayMsdSort-string-test.cpp
 *
 *    Description:  三路MSD字符串排序测试
 *
 *        Version:  1.0
 *        Created:  2011-11-3 8:43:54
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (),
 *        Company:
 *
 * =====================================================================================
 */

#include "SortProblem.h"
#include <ctime>
#include <iostream>
#include <fstream>
#include <iterator>

#define LARGE_COUNT 100000

int clock2milliseconds(const clock_t &start, const clock_t &finish)
{
    return (finish - start) / CLOCKS_PER_SEC * 1000;
}

int main(int argc, char *argv[])
{
    clock_t start, finish;
    std::ifstream file("string.txt");
    std::string val;
    std::vector<std::string> A;

    start = clock();

    while (file >> val) {
        if (val.length() > 256) {
            continue;
        }

        A.push_back(val);
    }

    finish = clock();
    std::cout << "the file read time is "
              << clock2milliseconds(start, finish)
              << " milliseconds."
              << std::endl;

    start = clock();
    threeWayMsdSort(A, 0, A.size() - 1);
    finish = clock();
    std::ofstream outFile("threeWayMsdSort-test.txt");
    std::cout << "threeWayMsdSort running time is "
              << clock2milliseconds(start, finish)
              << std::endl;
    std::copy(A.begin(), A.end(), std::ostream_iterator<std::string>(outFile, "\n"));
}

